<!-- 全部课程列表 -->
<template>
  <section class="container">
    <!-- 顶部导航栏开始 -->
    <div class="vod_box">
      <div class="filter-box">
        <div class="filter-back" @click.stop="backHome()">
          <img src="@/assets/img/icon-back.png" alt class="back" />
        </div>
        <div class="filter-title">录播课程</div>
        <div class="filter-button">
          <div class="button-text" @click.stop="show()">
            <span>筛选</span>
            <img src="@/assets/img/icon-filter.png" alt />
          </div>
          <div v-show="isShow">
            <div class="category2-box">
              <div class="item active">全部</div>
              <div class="item">前端开发</div>
              <div class="item">后端开发</div>
              <div class="item">移动开发</div>
              <div class="item">人工智能</div>
            </div>
            <div class="meedu-shadow-box" @click="hide()"></div>
          </div>
        </div>
      </div>
      <div class="category1-box">
        <div class="item" :style="{color:allColor,fontWeight:allFont}" @click="All()">全部</div>
        <div class="item" :style="{color:freeColor,fontWeight:freeFont}" @click="Free()">免费</div>
      </div>
    </div>
    <!-- 顶部导航栏结束 -->
    <div v-if="isFree">
      <KPCourseItem class="vod_course_item" v-for="j in freeCourse" :key="j.id" :item="j"></KPCourseItem>
    </div>
    <div v-else>
      <KPCourseItem class="vod_course_item" v-for="j in allCourseInfo.data" :key="j.id" :item="j"></KPCourseItem>
    </div>
  </section>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import KPCourseItem from "@/components/KPCourseItem.vue";

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    KPCourseItem
  },
  data() {
    //这里存放数据
    return {
      allCourseInfo: [],
      freeCourse: [],
      isFree: false,
      isShow: false,
      // font-weight: bolder;
      allColor: "#3ca7fa",
      allFont: "bolder",
      freeColor: "black",
      freeFont: ""
      // fontWeight: "bolder"
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    backHome: function() {
      this.$router.push({
        path: "/"
      });
    },
    Free: function() {
      // let btn = document.querySelectorAll("item");
      this.freeColor = "#3ca7fa";
      this.freeFont = "bolder";
      this.allColor = "black";
      this.allFont = "";
      this.isFree = true;
    },
    All: function() {
      this.isFree = false;
      this.allColor = "#3ca7fa";
      this.allFont = "bolder";
      this.freeColor = "black";
      this.freeFont = "";
    },
    show: function() {
      this.isShow = true;
    },
    hide: function() {
      this.isShow = false;
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  async created() {
    let res = await this.$request.get("/api/v2/courses");
    this.allCourseInfo = res.data;
    this.allCourseInfo.data.forEach(item => {
      if (item.is_free === 1) {
        this.freeCourse.push(item);
      }
    });
  },

  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang="less"  scoped>
.container {
  .vod_box {
    width: 100%;
    height: auto;
    float: left;
    box-sizing: border-box;
    padding: 0 15px;
    background-color: #fff;
    line-height: 30px;
    position: sticky;
    top: 0;
    z-index: 999;
    display: flex;
    flex-direction: column;
    .filter-box {
      width: 100%;
      height: 50px;
      background: #fff;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;

      .filter-back {
        .back {
          width: 24px;
          height: 24px;
        }
      }

      .filter-title {
        width: 72%;
        height: 18px;
        font-size: 18px;
        font-weight: 500;
        color: #171923;
        line-height: 18px;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .filter-button {
        .button-text {
          font-size: 14px;
          font-weight: 400;
          color: #333;
          cursor: pointer;
          span {
          }

          img {
            width: 24px;
            height: 24px;
            margin-left: 5px;
          }
        }
        .category2-box {
          position: absolute;
          top: 40px;
          right: 15px;
          z-index: 10080;
          width: 166px;
          height: auto;
          box-sizing: border-box;
          padding: 0 15px;
          border-radius: 5px;
          background-color: #fff;
          .item.active {
            width: 100%;
            height: auto;
            float: left;
            font-size: 14px;
            color: #333;
            line-height: 40px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }

          .item {
            width: 100%;
            height: auto;
            float: left;
            font-size: 14px;
            color: #333;
            line-height: 40px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
        .meedu-shadow-box {
          position: fixed;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          z-index: 997;
          background-color: rgba(0, 0, 0, 0.3);
        }
      }
    }

    .category1-box {
      width: 100%;
      height: 50px;
      background: #fff;
      display: flex;
      align-items: center;
      .item.active {
        color: #3ca7fa;
        font-weight: bolder;
      }

      .item {
        width: auto;
        height: auto;
        float: left;
        font-size: 16px;
        color: #666;
        margin-right: 16px;
      }
    }
  }
  .vod_course_item {
    width: 100%;
    height: auto;
    float: left;
    box-sizing: border-box;
    padding: 15px;
  }
}
</style>